package rush.rushcampus.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import rush.rushcampus.common.Result;
import rush.rushcampus.dto.UserDto;
import rush.rushcampus.entity.User;
import rush.rushcampus.service.IUserService;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author rush
 * @since 2024-06-11
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;
    //用户登录
    @ApiOperation(value = "用户登录")
    @PostMapping("/login")
    public Result login(HttpServletRequest request, @RequestBody UserDto userDto) {
        return userService.login(request , userDto);
    }
    //用户注册
    @ApiOperation(value = "用户注册")
    @PostMapping("/register")
    public Result register(@RequestBody UserDto userDto) {
        return userService.register(userDto);
    }

    //登出（待开发）
    @ApiOperation(value = "登出（待开发）")
    @GetMapping("/logout")
    public Result logout() {
        return Result.success();
    }

    //修改个人信息
    @ApiOperation(value = "修改个人信息")
    @PostMapping("/update")
    public Result update(@RequestBody User user) {
        return userService.updateById(user) ? Result.success() : Result.error("更新失败");
    }
}
